﻿@{
    Layout = "../_QuickLayoutPage.cshtml";
}
<div class="login-sign">会员登录</div>
<div id="LoginBox">
 <form method="post" id="loginForm" data-validate-params="tipsStyle:3" autocomplete="off">
                        <div class="validate-all-tips-box"></div>
                        <div class="form-group">
                            <div class="controls ">
                                <input type="text" id="username" name="username" class="form-control" maxlength="50" placeholder="@ViewBag.PlaceHolder" data-validate="dataType:'*',nullMsg:'请填写登录账号'">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <input type="password" id="password" name="password" class="form-control" maxlength="50" placeholder="登录密码" data-validate="dataType:'password',nullMsg:'请填写登录密码'">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        @if (ViewBag.VerificationCode == "1")
                        {
                            <div class="form-group">
                                <div class="controls">
                                    <div class="input-group">
                                        <input type="text" id="_VerificationCode" name="_VerificationCode" class="form-control" maxlength="4" placeholder="输入右侧的验证码" data-validate="dataType:'*',minLength:4,minLengthErrorMsg:'验证码最少4个字符',nullMsg:'请填写验证码',checkUrl:'/E/VerificationCode/Validate',checkError:'验证码填写错误'">
                                        <span class="input-group-btn">
                                            <a class="btn btn-default btn-verificationCodeImg"><img id="verificationCodeImg" src="/E/VerificationCode/?width=100&height=39" class="ui-verificationCodeImage" /></a>
                                        </span>
                                    </div>
                                    <span class="help-block" id="_ValidateTips__VerificationCode"></span>
                                </div>
                            </div>

                        }
                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-6 col-xs-6 hidden">
                                    <span><input id="cookies" type="checkbox" name="cookies" value="1"></span>
                                    <label for="cookies" class="font-weight-normal">&nbsp;记住我的登录信息</label>
                                </div>
                                <div class="col-md-12 col-xs-12 text-right">
                                    <a href="@Url.ActionUrl("quick","Reg")">注册会员</a>&nbsp;&nbsp;<a href="@Url.ActionUrl("Quick","FindPassword")">忘记密码?</a>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="controls controls-submit">
                                <button type="button" class="btn  btn-primary btn-lg col-xs-12 col-md-12  ui-pagePost" data-custom-params="url:'@Url.ActionUrl("Index")',callBack:'LoginSuccess',failCallBack:'FailCallBack',successMsg:''">登录</button>
                            </div>
                        </div>

                        <div class="form-group quickLogin hidden">
                            <h5>使用合作账户登录</h5>
                            <div>
                                <a class="quick-login-icon qq-icon" title="QQ登录"></a>
                                <a class="quick-login-icon weixin-icon" title="微信登录"></a>
                            </div>
                        </div>
                        @Html.AntiForgeryToken()
                    </form>
</div>
    <script type="text/javascript">
        var open =@ViewBag.Open;
        var logined = "@ViewBag.Logined";
        var $form = $("#loginForm");
        var $verificationCode = $("#_VerificationCode");
    var $loginBox = $("#LoginBox");
    //保存登录信息到本地
    function SaveInfo()
    {
        if ($("#cookies").prop("checked")) {
            var serializerStr = $form .SerializeJson();
            serializerStr = JsonToString(serializerStr);
            SetLocalStorage("LoginUserInfo", serializerStr);
        }
        else
        {
           RemoveLocalStorage("LoginUserInfo");
        }
    }
    //初始化
    function Init()
    {
        var serializerStr = GetLocalStorage("LoginUserInfo");
        $form.FormBind({}, serializerStr);
        $verificationCode.val("");
        if (open == 0) {
            $loginBox.text("对不起，网站登录已经关闭！");
        }
    }
        Init();

  function LoginSuccess(result)
   {
       SaveInfo();
            layer.msg('登录成功...', {
                icon: 16,
                time: 1500, //200秒
                shade: 0.1
            }, function () {
                if (typeof (parent.LoginSuccess) == "function") {
                    parent.LoginSuccess(result);
                }
                winClose();
            });
    }
        var $tipsBox = $(".validate-all-tips-box");

        function FailCallBack(data)
        {
            $tipsBox.text(data.Msg);
        }

        function winClose()
        {
            CloseDialog();
        }
        $("#closeBtn").on("click", function () { winClose(); });

        $(function () {AutoDialog(); })
        $(document).keyup(function (event)
        {
            if (event.keyCode == 13) {
                $(".ui-pagePost").trigger("click");
            }
        });
    </script>
